package com.feeyo.prophet.pojo.vo;

import com.feeyo.prophet.pojo.enums.ResultEnum;

import java.io.Serial;
import java.io.Serializable;

public class ResultVO<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;


    public ResultVO(T data, ResultEnum resultCodeEnum) {
        this.data = data;
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    public ResultVO(ResultEnum resultCodeEnum, String msg) {
        this.code = resultCodeEnum.getCode();
        this.msg = msg;
    }


    public static <T> ResultVO<T> sendSuccess(T data) {
        return new ResultVO<>(data, ResultEnum.SUCCESS);
    }

    public static <T> ResultVO<T> sendError(ResultEnum resultEnum) {
        return new ResultVO<>(null, resultEnum);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
